<template>
	<view class="commission-details" ref="container">
		<view class="promoterHeader bg-color-red">
			<view class="headerCon acea-row row-between-wrapper">
				<view>
					<view class="name">提现记录</view>
					<view class="money">
						￥
						<text class="num">{{ commission }}</text>
					</view>
				</view>
				<view class="iconfont icon-jinbi1"></view>
			</view>
		</view>
		<view class="sign-record" ref="content">
			<view class="list">
				<!-- <view class="item" v-for="(item, infoIndex) in info" :key="infoIndex">
					<view class="data">{{ item.time }}</view>
					<view class="listn" v-for="(val, indexn) in item.list" :key="indexn">
						<view class="itemn acea-row row-between-wrapper">
							<view>
								<view class="name line1">{{ val.title }}</view>
								<view>{{ val.addTime }}</view>
							</view>
							<view class="num" v-if="val.pm == 1">+{{ val.number }}</view>
							<view class="num font-color-red" v-if="val.pm == 0">-{{ val.number }}</view>
						</view>
					</view>
				</view> -->
				<view class="item" v-for="(item, infoIndex) in info" :key="infoIndex">
					<view class="listn">
						<view class="itemn acea-row row-between-wrapper" style="height: auto; padding: 6rpx 10rpx 6rpx 0;">
							<view>
								<view class="name line1">提现:{{ item.originalExtractPrice }}元</view>
								<view style="margin-bottom: 6rpx;">平台手续费:{{item.platformCharge}}元 提现手续费:{{item.withdrawCharge}}元</view>
								<view style="margin-bottom: 6rpx;">{{ item.createTime }}</view>
								<view style="margin-bottom: 6rpx; color: red;" v-if="item.failMsg">失败原因:{{item.failMsg}}</view>
							</view>
							<view class="num">+{{item.extractPrice}}</view>
							<view>{{ statusMap[item.status] }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<Loading :loaded="loaded" :loading="loading"></Loading>
	</view>
</template>
<script>
	// 使用新接口 yxUserExtract
	// getCommissionInfo, getSpreadInfo,
	import {
		yxUserExtract,
		extractSum
	} from "@/api/user";
	import Loading from "@/components/Loading";

	export default {
		name: "CashRecord",
		components: {
			Loading
		},
		props: {},
		data: function() {
			return {
				info: [],
				commission: 0,
				where: {
					page: 0,
					limit: 20
				},
				types: 4,
				loaded: false,
				loading: false,
				statusMap: {
					'-1': '未通过',
					'0': '审核中',
					'1': '已提现'
				}
			};
		},
		mounted: function() {
			this.getCommission();
			this.getIndex();
		},
		onReachBottom() {
			this.loading === false && this.getIndex();
		},
		methods: {
			getIndex: function() {
				let that = this;
				if (that.loading == true || that.loaded == true) return;
				that.loading = true;
				yxUserExtract(that.where).then(res => {
					console.log(res.data)
					that.loading = false;
					that.loaded = res.data.content.length < that.where.limit;
					that.where.page = that.where.page + 1;
					that.info.push.apply(that.info, res.data.content);
					console.log(that.info)
				}, err => {
					// uni.showToast({
					// 	title: err.msg || err.response.data.msg || err.response.data.message,
					// 	icon: 'none',
					// 	duration: 2000
					// });
				})
				//    getCommissionInfo(that.where, that.types).then(
				//      res => {
				//        that.loading = false;
				//        that.loaded = res.data.length < that.where.limit;
				//        that.where.page = that.where.page + 1;
				//        that.info.push.apply(that.info, res.data);
				//      },
				//      err => {
				//        uni.showToast({
				// 	title: err.msg || err.response.data.msg|| err.response.data.message,
				// 	icon: 'none',
				// 	duration: 2000
				// });
				//      }
				//    );
			},
			getCommission: function() {
				let that = this;
				extractSum().then(
					res => {
						that.commission = res.data;
					},
					err => {
						// uni.showToast({
						// 	title: err.msg || err.response.data.msg || err.response.data.message,
						// 	icon: "none",
						// 	duration: 2000
						// });
					}
				);
			}
		}
	};
</script>